package com.base.common.persistent.dao;

import com.base.common.persistent.model.Ticket;
import org.apache.ibatis.annotations.Param;

import java.util.Date;
import java.util.List;

/**
 * 工单dao
 * 
 * @author Administrator
 * 
 */
public interface TicketMapper {

	/**
	 * 添加工单
	 * 
	 * @param ticket
	 * @return
	 */
	int addTicket(Ticket ticket);

	/**
	 * 根据userId和工单分类查询工单信息并根据时间从新到旧降序排列分页查询工单列表
	 * 
	 * @param ticket
	 * @return
	 */
	List<Ticket> queryLastByCategoriesAndUserId(
			@Param(value = "start") int start, @Param(value = "end") int end,
			@Param(value = "categories") int categories,
			@Param(value = "userId") int userId);

	/**
	 * 查新最新的工单号根据工单类型
	 * 
	 * @param type
	 * @return
	 */
	List<Ticket> queryLastCodeByCategories(
			@Param(value = "categories") int categories);
	
	/**
	 * 根据工单的code查询工单信息
	 * 
	 * @param code
	 * @return
	 */
	Ticket queryTicketByCode(@Param(value = "code") String code);
	
	/**
	 * 根据员工id和工单进度类别查询工单条数
	 * 
	 * @param employeeId
	 * @param reportCategories
	 * @param ticketCategories
	 * @param aTime	时间段开始时间
	 * @param bTime	时间段结束时间
	 * @param status
	 * @return
	 */
	int queryTicketCountsByEmployeeIdAndReportCategories(
			@Param(value = "employeeId") int employeeId,
			@Param(value = "reportCategories") int reportCategories,
			@Param(value = "ticketCategories") int ticketCategories,
			@Param(value = "aTime") Date aTime,
			@Param(value = "bTime") Date bTime,
			@Param(value = "status") int status);
	
	/**
	 * 根据employeeId和工单分类查询工单信息并根据时间从新到旧降序排列分页查询工单列表
	 * 
	 * @param start
	 * @param end
	 * @param categories
	 * @param employeeId
	 * @return
	 */
	List<Ticket> queryTicketsByCategoriesAndEmployeeId(
			@Param(value = "start") int start, @Param(value = "end") int end,
			@Param(value = "categories") int categories,
			@Param(value = "employeeId") int employeeId);

	/**
	 * 根据员工id和工单进度类别分页查询工单列表
	 * 
	 * @param employeeId
	 * @param reportCategories
	 * @param status
	 * @param page
	 * @return
	 */
	List<Ticket> queryTicketsByEmployeeIdAndReportCategories(
			@Param(value = "employeeId") int employeeId,
			@Param(value = "reportCategories") int reportCategories,
			@Param(value = "ticketCategories") int ticketCategories,
			@Param(value = "aTime") Date aTime,
			@Param(value = "bTime") Date bTime,
			@Param(value = "status") int status,
			@Param(value = "start") int start, @Param(value = "end") int end);

	/**
	 * 根据工单类别和员工id查询工单总数
	 * 
	 * @param ticket
	 * @return
	 */
	int queryTotalByCategoriesAndEmployeeId(Ticket ticket);

	/**
	 * 根据userId和工单分类查询工单信息并根据时间从新到旧降序排列分页查询工单列表总数
	 * 
	 * @param ticket
	 * @return
	 */
	int queryTotalByCategoriesAndUserId(Ticket ticket);

	/**
	 * 根据工单id更新类别
	 * 
	 * @param ticket
	 * @return
	 */
	int updateCategoriesById(@Param(value = "id") int id, @Param(value = "categories") int categories);

	/**
	 * 更新工单图片地址
	 * 
	 * @param code
	 * @param picUrls
	 * @return
	 */
	int updatePicUrlsByCode(
			@Param(value = "code") String code,
			@Param(value = "picUrls") String picUrls);
	
	/**
	 * 根据工单id更新状态
	 *
	 * @return
	 */
	int updateScoreById(@Param(value = "id") int id, @Param(value = "score") int score);

	/**
	 * 根据工单id更新状态
	 * 
	 * @return
	 */
	int updateStatusById(@Param(value = "id") int id, @Param(value = "status") int status);

	/**
	 *
	 * @param id
	 * @param code
     * @return
     */
	int updateCodeById(@Param(value = "id") int id, @Param(value = "code") String code);

	int updateEmployeeCompoundsByTicketId(@Param(value = "employeeCompoundsId") int employeeCompounds, @Param(value = "id") int id);
}
